//
//  FirstViewController.swift
//  VCTranstion
//
//  Created by 李煜 on 2024/9/13.
//

import UIKit

class FirstViewController: UIViewController, UIViewControllerTransitioningDelegate {
  override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = .systemPink
  }
  
  override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    super.touchesBegan(touches, with: event)
    //转场
    presentModal()
  }
  func presentModal() {
    let secondVC = SecondViewController()
    secondVC.modalPresentationStyle = .custom
    secondVC.transitioningDelegate = self
    present(secondVC, animated: true, completion: nil)
  }
  
  //MARK: - UIViewControllerTransitioningDelegate
  func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    return CustomModalTransition()
  }
  
  func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
    return CustomModalTransition() // 也可以实现dismiss动画
  }
}


